﻿    
    /*
函数介绍：
	navShow：
			当鼠标划过时改变导航栏状态
		参数表：
		arguments[0]：要被改变的图片元素的ID
		arguments[1]：要被改变的中间分隔线的ID列表字符串(用‘,’号隔开，处理里需要分隔字符串)
		(参数解释适用于navhidden函数)
		
	navhidden：
			当鼠标划离时把状态栏变回原来的样子
		参数表：
			如上述……
*/

function navShow(){
	//arguments[0]
	/*
		alert(c);
	*/
	var navId = arguments[0];
	var lineStr = arguments[1];
	
	var navIdObject = document.getElementById(navId);
	var navStr = navIdObject.src;
	var navEndStr = navStr.replace(/[A,B].gif/,"B.gif");
	navIdObject.src = navEndStr;
	
	var lineArr = lineStr.split(",");
	for(var i=0; i<lineArr.length; i++)
	{
		document.getElementById(lineArr[i]).className = "varLineRed";
	}
}

function navhidden()
{
	var navId = arguments[0];
	var lineStr = arguments[1];
	
	var navIdObject = document.getElementById(navId);
	var navStr = navIdObject.src;
	var navEndStr = navStr.replace(/[A,B].gif/,"A.gif");
	navIdObject.src = navEndStr;

	var lineArr = lineStr.split(",");
	for(var i=0; i<lineArr.length; i++)
	{
		document.getElementById(lineArr[i]).className = "varLine";
	}
	

}
function On(name,value)
{
    var Days = 1;
    var exp  = new Date();    //new Date("December 31, 9998");
        exp.setTime(exp.getTime() + Days*24*60*60*1000);
        document.cookie = name + "="+  value + ";expires=" + exp.toGMTString();
}

function getObjects(id) {
    if (document.getElementById) {
        return document.getElementById(id);
    } else if (document.all) {
        return document.all[id];
    } else if (document.layers) {
        return document.layers[id];
    }
}
function Trim() {
    return this.replace(/\s+$|^\s+/g, "");
}
String.prototype.Trim = Trim;

function getObjValues(id) {
    if (getObjects(id).value != undefined)
        return getObjects(id).value.Trim();
    else
        return "";
}
function createXMLHttpRequest() {
    if (window.XMLHttpRequest) {
        XMLHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {//IE 浏览器
        try {
            XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                XMLHttpReq = new ActiveXObject("Micrsost.XMLHTTP");
            } catch (e) { }
        }
    }
}

function checkForms() {
    if (getObjValues("uname") == "" || getObjValues("txtcomment") == "") {
        alert("昵称和评论内容不能为空！");
        return false;
    }
    if (getObjValues("uname").length > 20) {
        alert("昵称不能大于20字！");
        return false;
    }
    if (getObjValues("txtcomment").length > 200) {
        alert("评论内容不能大于200字！");
        return false;
    }
    /*if (getObjValues("sCode") == "") {
        alert("请输入验证码！");
        return false;
    }*/
    return true;
}

function comm_put(id,a,ctype){
         if(checkForms()){
         createXMLHttpRequest();
         if(ctype=="message")
       	 {
       	 	XMLHttpReq.open("POST","../Inc/CmsComm_Ajax.aspx?id="+id+"&a="+a+"&type="+ctype,true);
       	 }
       	 else
       	 {
             XMLHttpReq.open("POST","../Inc/CmsComm_Ajax.aspx?id="+id+"&a="+a,true);
       	 }
         XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
         XMLHttpReq.onreadystatechange=function(){
             if (XMLHttpReq.readyState == 4) {
                 document.getElementById("uname").value = "";//这个可以用
                 document.getElementById("uemail").value = "";
                 document.getElementById("txtcomment").value = "";
                 document.getElementById("msg_form").innerHTML = XMLHttpReq.responseText;  

                 if (XMLHttpReq.status == 200) {
                     document.getElementById("uname").value = "";//这个可以用
                     document.getElementById("uemail").value = "";
                     document.getElementById("txtcomment").value = "";
                 document.getElementById("msg_form").innerHTML = XMLHttpReq.responseText;

              var msg=unescape(XMLHttpReq.responseText);
              if(msg == "Err_100"){
		  window.alert("非法操作！");
	      }else if(msg == "Err_101"){
		  window.alert("你发表的内容中包含系统禁止字符！");
	      }else if(msg == "Err_102"){
		  window.alert("请输入正确的验证码！");
	      }else{
                  document.getElementById("commBody").innerHTML=msg;
              }
         }else{
             window.alert("您请求的页面出现异常错误！！");	
              }
         }
   }
         var uname = escape(getObjValues("uname"));
         var txtcomment = escape(getObjValues("txtcomment"));
         var uemail=escape(getObjValues("uemail"));
         XMLHttpReq.send("uname=" + uname + "&txtcomment=" + txtcomment + "&uemail=" + uemail + "&do=add");
         //var scode = escape(getObjValues("sCode"));
         //XMLHttpReq.send("uname="+uname+"&txtcomment="+txtcomment+"&scode="+scode+"&do=add");
   }
}
function killErr() { return true; }
window.onerror = killErr;

